package com.yunlong.token;

import com.yunlong.common.TokenInfo;
import com.yunlong.redis.RedisRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ycSong
 */
@Service
public class TokenServiceImpl implements TokenService {

    @Resource
    private RedisRepository redisRepository;

    @Override
    public TokenInfo getTokenInfo(String accessToken) {
        String userId = redisRepository.selectAccessToken(accessToken);
        if (userId != null) {
            TokenInfo tokenInfo = new TokenInfo();
            tokenInfo.setUserId(userId);
            tokenInfo.setAccessToken(accessToken);
            return tokenInfo;
        }
        return null;
    }

    @Override
    public TokenInfo getManagerInfo(String accessToken) {
        String userId = redisRepository.selectManagerId(accessToken);
        if (userId != null) {
            TokenInfo tokenInfo = new TokenInfo();
            tokenInfo.setUserId(userId);
            tokenInfo.setAccessToken(accessToken);
            return tokenInfo;
        }
        return null;
    }
}
